package com.ccsu.joysport.entity;


import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.UUID;


@Entity
public class Club {

    @Id
    private String clubId;

    private String clubName;
    private String clubDesc;
    private String clubLogo;
    private String college;
    private int memberCount;
    private Timestamp clubCreate;
    private String clubUser;
    private String clubUserName;
    private String entryRestrictions;

    // 俱乐部申请原因
    private String applyReason;
    // 俱乐部状态 approve、wait、reject
    private String status;
    // 审核备注
    private String reviewRemark;
    // 创建时间
    private Date gmtCreate;
    // 修改时间
    private Date gmtModified;

    public String getApplyReason() {
        return applyReason;
    }

    public void setApplyReason(String applyReason) {
        this.applyReason = applyReason;
    }

    @OneToMany(mappedBy = "club")
    @JsonManagedReference
    private List<PastActivity> pastActivities;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getReviewRemark() {
        return reviewRemark;
    }

    public void setReviewRemark(String reviewRemark) {
        this.reviewRemark = reviewRemark;
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public Date getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(Date gmtModified) {
        this.gmtModified = gmtModified;
    }

    @PrePersist
    private void ensureId() {
        if (this.clubId == null) {
            this.clubId = UUID.randomUUID().toString();
        }
        if (this.clubCreate == null) {
            this.clubCreate = new Timestamp(System.currentTimeMillis());
        }
        if (this.gmtCreate == null) {
            this.gmtCreate = new Date(System.currentTimeMillis());
        }
        if (this.gmtModified == null) {
            this.gmtModified = new Date(System.currentTimeMillis());
        }
    }

    // Getters and setters
    public String getClubUser() {
        return clubUser;
    }

    public void setClubUser(String clubUser) {
        this.clubUser = clubUser;
    }


    public Timestamp getClubCreate() {
        return clubCreate;
    }
    public String getFormattedClubCreate() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(clubCreate);
    }

    public void setClubCreate(Timestamp clubCreate) {
        this.clubCreate = clubCreate;
    }


    public String getClubId() {
        return clubId;
    }

    public void setClubId(String clubId) {
        this.clubId = clubId;
    }

    public String getClubName() {
        return clubName;
    }

    public void setClubName(String clubName) {
        this.clubName = clubName;
    }

    public String getClubDesc() {
        return clubDesc;
    }

    public void setClubDesc(String clubDesc) {
        this.clubDesc = clubDesc;
    }

    public String getClubLogo() {
        return clubLogo;
    }

    public void setClubLogo(String clubLogo) {
        this.clubLogo = clubLogo;
    }

    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public int getMemberCount() {
        return memberCount;
    }

    public void setMemberCount(int memberCount) {
        this.memberCount = memberCount;
    }

    public List<PastActivity> getPastActivities() {
        return pastActivities;
    }

    public void setPastActivities(List<PastActivity> pastActivities) {
        this.pastActivities = pastActivities;
    }

    public String getEntryRestrictions() {
        return entryRestrictions;
    }

    public void setEntryRestrictions(String entryRestrictions) {
        this.entryRestrictions = entryRestrictions;
    }

    public String getClubUserName() {
        return clubUserName;
    }

    public void setClubUserName(String clubUserName) {
        this.clubUserName = clubUserName;
    }
}


